<?php
/**
 * 通用分页类
 *
 * 生成分页数组 , limit sql
 * @version 1.0
 */
class Pagination{
   /**
    * current page number
    * @var number
    */
	public $pageNow;

   /**
    * previous page number
    * @var number
    */
	public $pagePre;

   /**
    * next page number
    * @var number
    */
	public $pageNext;

   /**
    * start page
    * @var number
    */
	public $pageFirst;

	/**
    * next page number
    * @var number
    */
	public $pageLast;
	
   /**
    * total pages
    * @var number
    */
	public $totalPages;
   /**
    * total data rows
    * @var number
    */
    public $totalRows;
	/**
    * per page data rows
    * @var number
    */
    public $perPageRows;
    
    public function __construct($pageNow = 1,$totalRows,$perPageRows){
    	
    	$this->totalRows   = $totalRows;
    	$this->perPageRows = $perPageRows;
    	
    	$this->totalPages = ceil($this->totalRows/$this->perPageRows);
    	$this->pageFirst = '1';
    	$this->pageLast  = $this->totalPages;

    	if($pageNow <= 1){
    		$this->pageNow  = 1;
	    	$this->pagePre  = 1;
    		$this->pageNext = 2;
    	}elseif($pageNow >= $this->totalPages){
    		$this->pageNow  = $this->totalPages;
	    	$this->pagePre  = $this->totalPages - 1;
    		$this->pageNext = $this->totalPages;
    	}else{
    		$this->pageNow  = $pageNow;
	    	$this->pagePre  = $pageNow - 1;
    		$this->pageNext = $pageNow + 1;
    	}
    	
    	$this->sql = "LIMIT ".$perPageRows*($pageNow-1).",".$perPageRows*($pageNow);
    	return $this;
    }
}
?>